﻿#include "serialapp.h"

#include <QMouseEvent>

SerialApp::SerialApp(int& argc, char**& argv) : QApplication(argc, argv) {}


bool SerialApp::event(QEvent* event)
{
	// 事件类型是移动鼠标
	if (event->type() == QEvent::MouseMove)
	{
		QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
		QPointF p = mouseEvent->pos(); // 获取鼠标位置
		QPoint currentMousePoint = p.toPoint();
		emit SendCurrentMousePoint(currentMousePoint); // 发送信号到主界面
	}

	return QApplication::event(event);
}



bool SerialApp::notify(QObject* obj, QEvent* event)
{
	if (event->type() == QEvent::MouseMove)
	{
		QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);

		//QString mouse_info = QString("mouse pos: %1, %2").arg(mouseEvent->pos().x()).arg(mouseEvent->pos().y());

		//statusBar()->showMessage(mouse_info);
		QPointF p = mouseEvent->pos(); // 获取鼠标位置
		QPoint currentMousePoint = p.toPoint();

        currentMousePoint = QCursor::pos();
		emit SendCurrentMousePoint(currentMousePoint); // 发送信号到主界面
	}

	return QApplication::notify(obj, event);
}
